#! /usr/bin/python

import statFuncs
import sys

if __name__ == '__main__':
	stat		= statFuncs.statFuncs()
	dataTable	= {}
	avgTable	= {}
	numItems	= 0

	if len(sys.argv) != 2:
		print 'Usage: ./movingAvg avg_factor'
	else:
		factor	= int(sys.argv [1])

		for line in sys.stdin:
			items	= line.split('\t')
			if len(dataTable) == 0:
				numItems	= len(items)
				for i in range(0, len(items)):
					dataTable [i]	= []

			for i in range(0, numItems):
				if i != 0:
					dataTable [i].append(float(items [i]))
				else:
					dataTable [i].append(items [i])

		for pKey in dataTable:
			if pKey != 0:
				avgTable [pKey]	= stat.movingAvg(dataTable [pKey], factor)

		for i in range(factor-1, len(dataTable [0])):
			for key in dataTable:
				print dataTable [key][i],
				print '\t',
				if key != 0:
					print avgTable [key][i-factor+1],
					print '\t',
			print '\n',
